//
//  USTarotCardManager.m
//  us
//
//  Created by karry on 2025/5/14.
//

#import "USTarotCardManager.h"

@implementation USTarotCardManager

+ (instancetype)sharedManager {
    static USTarotCardManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[USTarotCardManager alloc] init];
        [manager loadCards];
    });
    return manager;
}

- (void)loadCards {
    // 你可以从 JSON 文件或 plist 里加载数据，这里用 hardcode 简化
    NSMutableArray *cards = [NSMutableArray array];

    NSArray<NSString *> *tarotNames = @[
        @"魔法师", @"愚人", @"女祭司",
        @"星币侍从", @"星币骑士", @"星币皇后", @"星币皇帝", @"星币10", @"星币9", @"星币8", @"星币7", @"星币6", @"星币5", @"星币4", @"星币3", @"星币2", @"星币1皇牌",
        @"圣杯侍从", @"圣杯骑士", @"圣杯皇后", @"圣杯皇帝", @"圣杯10", @"圣杯9", @"圣杯8", @"圣杯7", @"圣杯6", @"圣杯5", @"圣杯4", @"圣杯3", @"圣杯2", @"圣杯1皇牌",
        @"权杖侍从", @"权杖骑士", @"权杖皇后", @"权杖皇帝", @"权杖10", @"权杖9", @"权杖8", @"权杖7", @"权杖6", @"权杖5", @"权杖4", @"权杖3", @"权杖2", @"权杖1皇牌",
        @"宝剑侍从", @"宝剑骑士", @"宝剑皇后", @"宝剑皇帝", @"宝剑10", @"宝剑9", @"宝剑8", @"宝剑7", @"宝剑6", @"宝剑5", @"宝剑4", @"宝剑3", @"宝剑2", @"宝剑1皇牌",
        @"世界", @"审判", @"太阳", @"月亮", @"星星", @"高塔", @"恶魔", @"节制", @"死神", @"倒吊人", @"正义", @"命运之轮", @"隐士", @"力量", @"战车", @"恋人", @"教皇", @"皇帝", @"皇后"
    ];

    for (NSString *name in tarotNames) {
        USTarotCard *model = [[USTarotCard alloc] init];
        model.name = name;
        model.imageName = name;
        [cards addObject:model];
    }

    self.allCards = cards;
}

- (USTarotCard *)drawRandomCard {
    NSUInteger count = self.allCards.count;
    if (count == 0) return nil;

    NSUInteger index = arc4random_uniform((uint32_t)count);
    USTarotCard *original = self.allCards[index];

    // 复制一份以避免影响原数据
    USTarotCard *copy = [[USTarotCard alloc] init];
    copy.name = original.name;
    copy.imageName = original.name;
    copy.orientation = arc4random_uniform(2) == 0 ? USTarotCardOrientationUpright : USTarotCardOrientationReversed;
    copy.date = NSDate.date;
    return copy;
    
}


@end
